﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using AllInOne.Entity;
using PropertyChanged;

using MessageBox = HandyControl.Controls.MessageBox;

namespace AllInOne.MainPages
{
    /// <summary>
    /// 备案信息输入
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class PutOnRecordInPut : Page
    {
        public Record RecordModel { get; set; }

        //public List<MaterialModel> Materials { get; set; }
        public int MaterialSelectIndex { get; set; }

        public event DlgDialog DlgDialogEvent_InputPlate;

        public List<ProvinceAbbModel> Provinces { get; set; }
        public int ProvinceSelectIndex { get; set; } = 0;

        public int UserSelectIndex { get; set; }



        private MainWindow parent;

        public PutOnRecordInPut(MainWindow parent)
        {
            InitializeComponent();
            this.parent = parent;
        }
        public void InitPage(string strYNumber)
        {
            if (!string.IsNullOrEmpty(strYNumber) && strYNumber.Contains("XX"))
            {
                txtYNumber.Text = "";
            }
            else
            {
                txtYNumber.Text = strYNumber;
            }
            
            //if (this.parent.businessInfo.sjhm != null)
            //{
            //    this.txtSjhm.Text = this.parent.businessInfo.sjhm;
            //}
            //else
            //{
            //    this.txtSjhm.Text = this.parent.drivingLicence.sjhm;
            //}
            //this.imgTitle.Source = new BitmapImage(new Uri(this.parent.businessInfo.getImgTitleUrl()));

        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void BtnBackToIndex_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ////关闭页面，返回到上一级页面
            ////this.Close();
            //this.parent.ResetIndex();
            BtnSubmit_MouseUp(null, null);
        }

        private void setBackgroundImage(object sender, string url)
        {
            TextBlock btn = (TextBlock)sender;
            btn.Background = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri(url)),
                Stretch = Stretch.Uniform
            };
        }

        private void BigBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/big_btn.png");
        }

        private void BigBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/big_btn_hover.png");
        }

        private void BigBtn_MouseUp(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/big_btn.png");
            TextBlock btn = (TextBlock)sender;
            //this.txtPrefix.Text = btn.Text;
        }

        private void SmallBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/small_btn.png");

        }

        private void SmallBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/small_btn_hover.png");
        }

        private void SmallBtn_MouseUp(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/small_btn.png");

            TextBlock btn = (TextBlock)sender;
            string YNumber = this.txtYNumber.Text;
            //if (YNumber.Length < 6 || (YNumber.Length < 7 && (YNumber.Substring(1, 1) == "D" || YNumber.Substring(1, 1) == "F")))
            //{

            //}
            this.txtYNumber.Text = YNumber + btn.Text;
        }

        private void DeleteBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/delete_btn.png");

        }

        private void DeleteBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/delete_btn_hover.png");
        }

        private void DeleteBtn_MouseUp(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/delete_btn.png");
            if (this.txtYNumber.Text.Length > 0)
            {
                string carNumber = this.txtYNumber.Text;
                this.txtYNumber.Text = carNumber.Substring(0, carNumber.Length - 1);
            }
        }

        private void ClearBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/clear_btn.png");

        }

        private void ClearBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/clear_btn_hover.png");

        }

        private void ClearBtn_MouseUp(object sender, MouseButtonEventArgs e)
        {
            this.setBackgroundImage(sender, "pack://application:,,,/images/clear_btn.png");
            this.txtYNumber.Text = "";
        }

        private void BtnSubmit_MouseUp(object sender, MouseButtonEventArgs e)
        {
            string YNumber = this.txtYNumber.Text;
            //回到上一级菜单页面
            this.parent.GiveCard_Page_R(YNumber);
            //if (this.verifyYNumber())
            //{
            //    string YNumber = this.txtYNumber.Text;
            //    //回到上一级菜单页面
            //    this.parent.GiveCard_Page_R(YNumber);
            //}
            //else { MessageBox.Show("提示", "您输入的备案号不正确，请检查您的输入。"); }
        }

        /// <summary>
        /// 校验输入的数据
        /// </summary>
        /// <returns></returns>
        private bool verifyYNumber()
        {
            string carNumber = this.txtYNumber.Text;
            if (carNumber.Length >= 6)
            {
                return true;
            }
            return false;
        }
    }
}
